﻿using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace SeleniumTest
{
    [TestClass]
    public class TestProfile
    {
        private ChromeDriver driver;
        string path;
        private string url = "http://localhost:8080";
        [TestInitialize]
        public void Setup()
        {
            string projectname = "seleniumtesting111";
            string path = Directory.GetCurrentDirectory().Substring(0, Directory.GetCurrentDirectory().LastIndexOf(@"seleniumtesting111") + projectname.Length);
            ChromeOptions incognito = new ChromeOptions();
            incognito.AddArgument("--incognito");
            driver = new ChromeDriver(path, incognito);
            driver.Navigate().GoToUrl(url);
        }

        [TestCleanup]
        public void CleanUp()
        {
            driver.Quit();
        }

        [TestMethod]
        public void Login()
        {
            driver.FindElementByClassName("signin").Click();
            driver.FindElementById("login").SendKeys("seleniumtest@showyoucare.dk");
            driver.FindElementById("password").SendKeys("showyoucare");
            driver.FindElementById("signin_menu").FindElement(By.Name("submit")).Click();
            Assert.AreEqual("SELENIUM", driver.FindElementByClassName("signin").Text);
        }

        [TestMethod]
        public void ProfilePictureNotNull()
        {
            driver.FindElementByClassName("signin").Click();
            driver.FindElementById("login").SendKeys("seleniumtest@showyoucare.dk");
            driver.FindElementById("password").SendKeys("showyoucare");
            driver.FindElementById("signin_menu").FindElement(By.Name("submit")).Click();
            var img = driver.FindElementById("profile_context").FindElement(By.TagName("img"));
            Assert.IsTrue(!img.Size.IsEmpty);
        }

        [TestMethod]
        public void MyPageAvaiable()
        {
            driver.FindElementByClassName("signin").Click();
            driver.FindElementById("login").SendKeys("seleniumtest@showyoucare.dk");
            driver.FindElementById("password").SendKeys("showyoucare");
            driver.FindElementById("signin_menu").FindElement(By.Name("submit")).Click();
            driver.Navigate().GoToUrl(url+"/min-side");
            Assert.IsNotNull(driver.FindElementByClassName("profile"));
        }
    }
}
